<?php

namespace App\Http\Controllers\BaseData;

use App\Http\Conf\ResultInfo;
use App\Http\Controllers\Controller;
use App\Http\Models\CategoryBig;
use App\Http\Requests\CategoryBigRequest;

class CategoryBigController extends Controller
{
    public function index()
    {
        $models = CategoryBig::all();
        return view('base_data.category_big.index', ['models' => $models]);
    }

    public function create()
    {
        return view('base_data.category_big.create');
    }

    public function store(CategoryBigRequest $request)
    {
        $model = new CategoryBig();
        $model->name = $request->name;
        if ($model->save()) {
            return redirect()->action('BaseData\CategoryBigController@show', $model);
        } else {
            dd("添加数据有异常！");
        }
    }

    public function show($id)
    {
        $model = CategoryBig::find($id);
        return view('base_data.category_big.show', ['model' => $model]);
    }

    public function edit($id)
    {
        $model = CategoryBig::find($id);
        return view('base_data.category_big.edit', ['model' => $model]);
    }

    public function update(CategoryBigRequest $request, $id)
    {
        $model = CategoryBig::find($id);
        $model->name = $request->name;
        if ($model->save()) {
            return redirect()->action('BaseData\CategoryBigController@show', $model);
        } else {
            dd("编辑数据有异常！");
        }
    }

    public function destroy($id)
    {
        $model = CategoryBig::find($id);
        if ($model->delete()) {
            return ['status' => ResultInfo::SUCCESS];
        } else {
            return ['status' => ResultInfo::UNKNOWN];
        }
    }
}
